# 数值型矩阵转置
x1 <- matrix(1:9, 3)
x1

t(x1)

class(x1)
class(t(x1))

# 字符串类型矩阵转置
x2 <- matrix(LETTERS[1:9], 3)
x2

t(x2)

class(x2)
class(t(x2))

# 数据框（全数值）
x3 <- data.frame(a=1:3, b=4:6, c=7:9)
x3

t(x3)

class(x3)
class(t(x3))

# 混合型数据框转置

x4 <- data.frame(Name=c("A","B","C"), Score=c(70,80,90))
x4

str(x4)

t(x4)

class(t(x4))


# 如何避免
as.data.frame(t(x4))

class(as.data.frame(t(x4)))
str(x4)

# ------------------------------------------
# 准备工作
# ------------------------------------------

setwd("/Users/eimei/Documents/Rdata/")  # 设定工作空间
data <- read.csv("HRdata.csv")  # 读取数据

newdata <- data[c("EmployeeNumber", "Age", "Department",
                  "EnvironmentSatisfaction", "JobSatisfaction",
                  "MonthlyIncome", "RelationshipSatisfaction")]

head(newdata)

# ------------------------------------------
# 任务一
# ------------------------------------------
temp <- newdata[1:10, ]
t(temp)

str(as.data.frame(t(temp)))